package cn.itcast.order;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    /**
     * 1）创建RestTemplate，注入到IOC容器
     * 2）直接在程序中注入RestTemplate，使用它
     * 3）远程调用  restTemplate.getForObject("远程地址",返回数据需要转换的JavaBean的字节码)
     *             User user = restTemplate.getForObject("http://localhost:8081/user/1",User.class)
     */
    @LoadBalanced   //支持负载均衡，会将替换IP端口的字符串当做服务名字
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

}